<template>
  <div class="market">
    <!-- <div class="title flex flex-cc flex-rb mb-15">
      <div class="flex">
        <van-button
          class="mr-10"
          style="width: 100px; height: 35px"
          type="default"
          round
          v-for="(v, i) in tabs"
          :key="i"
          @click="tabIndex = i"
        >
          {{ v }}
        </van-button>
      </div>

      <div class="cl-basic">{{ $t('市场下级') }}</div>
    </div> -->

    <div class="box-white p-20 bcl-bg mb-10 fz-12">
      <div class="bd-bottom pb-10 mb-10" style="border-color: #ebebeb">
        <img style="width: 20px" :src="getLevelIconUrl(detail?.level_user)" />
      </div>

      <div class="flex flex-wrap">
        <div style="width: 50%">
          <span class="cl-basic mr-5">{{ $t('直推业绩') }}:</span>
          <span>{{ toFixed(detail?.parent_amount) }} U</span>
        </div>
        <div style="width: 50%">
          <span class="cl-basic mr-5">{{ $t('间推收益') }}:</span>
          <span>{{ toFixed(detail?.grand_amount) }} U</span>
        </div>
        <div style="width: 50%">
          <span class="cl-basic mr-5">{{ $t('大市场业绩') }}:</span>
          <span>{{ toFixed(detail?.big) }} U</span>
        </div>
        <div style="width: 50%">
          <span class="cl-basic mr-5">{{ $t('小市场业绩') }}:</span>
          <span>{{ toFixed(detail?.small) }} U</span>
        </div>
        <div>
          <span class="cl-basic mr-5">{{ $t('更新时间') }}:</span>
          <span v-if="detail?.updatetime">
            {{ formatDateTime(detail?.updatetime) }}
          </span>
          <span v-else>{{ $t('无') }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { formatDateTime, toFixed } from 'js/utils'
import api from 'js/api'

const tabs = ref([`${$t('直推')} 0`, `${$t('间推')} 0`])
const detail = ref({})

getMarketDetail()

// 获取市场详情
async function getMarketDetail() {
  const { code, data } = await api.getMarketDetail()

  if (code === 1) {
    tabs.value[0] = `${$t('直推')} ${data.parent_cnt}`
    tabs.value[1] = `${$t('间推')} ${data.grand_cnt}`
    detail.value = data
  }
}

function getLevelIconUrl(level) {
  return new URL(`../assets/img/icon_v${level}.png`, import.meta.url).href
}
</script>

<style lang="scss" scoped></style>
